<!doctype html>
<html lang="zh-CN">
{include file='base/header' /}

<body class="fixed-sidebar full-height-layout gray-bg pace-done" style="overflow:hidden">
<div id="wrapper">

    {include file='base/left' /}

    <div id="page-wrapper" class="gray-bg dashbard-1">

        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#">
                        <i class="fa fa-bars"></i>
                    </a>
                </div>

                <ul class="nav navbar-top-links navbar-right">
                    <li>
                        <span class="m-r-sm text-muted welcome-message">
                            <a href="{:url('index/index')}" title="返回首页">
                                <i class="fa fa-home"></i>
                            </a>欢迎使用广州博学教育系统
                        </span>
                    </li>

                    <li>
                        <a href="{:url('index/logout')}">
                            <i class="fa fa-sign-out"></i> 退出
                        </a>
                    </li>
                </ul>
            </nav>
        </div>

        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-sm-12">
                {block name="breadcrumb"}{/block}
            </div>
        </div>

        <div class="wrapper wrapper-content">

            {block name="search"}{/block}

            <div class="row">
                <div class="col-lg-12">
                    {block name="main"}主内容{/block}
                </div>
            </div>

            <!-- 底部 -->
            <!--<div class="footer">-->
            <!--<div class="pull-right">-->
            <!--By：<a href="#">广州博学教育</a>-->
            <!--</div>-->
            <!--</div>-->
        </div>
    </div>
</div>

<!-- Mainly scripts -->
{load href="/static/js/jquery.min.js" /}
{load href="/static/js/bootstrap.min.js" /}
{load href="/static/js/plugins/metisMenu/jquery.metisMenu.js" /}
{load href="/static/js/plugins/slimscroll/jquery.slimscroll.min.js" /}
{load href="/static/js/plugins/layer/layer.min.js" /}
{load href="/static/js/hplus.js" /}

<!-- 加载其他js -->
{block name="jsFile"}{/block}
<script>
    // 删除操作
    $('.delete-one').click(function () {
        let id = $(this).data('id');
        let url_tmp = "{:url('delete', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        layer.confirm('您确定要删除该数据吗', {}, function () {
            $.ajax({
                url: url,
                data: {},
                type: 'POST',
                success: function (e) {
                    layer.msg('删除成功', {icon: 1});
                    window.location.href = e.data.url;
                },
                error: function () {
                    layer.msg('删除失败', {icon: 2});
                }
            })
        });
    });
    // 添加标识码
    $('.addAgent-one').click(function () {
        let id = $(this).data('id');
        let url_tmp = "{:url('addAgent', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        var phone=prompt("请输入你要绑定的手机号码");
        if (phone == null) {
            alert('请输入要绑定的手机号码');
            return false;
        }
        $.ajax({
            url: url,
            data: {
                id: id,
                phone:phone
            },
            type: 'POST',
            success: function (e) {
                if (e.code == 0) {
                    layer.msg('绑定成功', {icon: 1});
                    etTimeout(function() { window.location.href =  e.data.url; }, 2000 );
                } else {
                    layer.msg('绑定失败',  {icon: 2});
                }

                // setTimeout(window.location.href = e.data.url,3000);


            },
            error: function () {
                layer.msg(e.data.msg, {icon: 2});
            }
        })
        // layer2.confirm('您确定要生成分享码吗', {}, function () {
        //     $.ajax({
        //         url: url,
        //         data: {},
        //         type: 'POST',
        //         success: function (e) {
        //             layer2.msg(e.data.msg, {icon: 1});
        //             // setTimeout(window.location.href = e.data.url,3000);
        //             setTimeout(function() { window.location.href =  e.data.url; }, 2000 );
        //
        //         },
        //         error: function () {
        //             layer2.msg('生成失败', {icon: 2});
        //         }
        //     })
        // });
    });
    // 添加用户备注
    $('.updateNote-one').click(function () {
        let id = $(this).data('id');

        let url_tmp = "{:url('updateNote', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        var note=prompt("备注");
        if (note == null) {
            alert('请输入备注');
            return false;
        }
        $.ajax({
            url: url,
            data: {
                id: id,
                note:note
            },
            type: 'POST',
            success: function (e) {
                if (e.code == 0) {
                    layer.msg('操作成功', {icon: 1});
                    window.location.href = e.data.url;
                } else {
                    layer.msg('操作失败',  {icon: 2});
                }

                // setTimeout(window.location.href = e.data.url,3000);


            },
            error: function () {
                layer.msg(e.data.msg, {icon: 2});
            }
        })
    });
    // 添加标识码
    $('.updateSet-one').click(function () {

        let id = $(this).data('id');
        let url_tmp = "{:url('updateSet', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        $.ajax({
            url: url,
            data: {
                id: id,
            },
            type: 'POST',
            success: function (e) {
                if (e.code == 0) {

                    layer.msg('操作成功', {icon: 1});
                    window.location.href = e.data.url;
                } else {
                    layer.msg('操作失败',  {icon: 2});
                }

                // setTimeout(window.location.href = e.data.url,3000);


            },
            error: function () {

                layer.msg(e.data.msg, {icon: 2});
            }
        })
    });
    // 修改状态
    $('.disabled-one').click(function () {
        let id = $(this).data('id');
        let url_tmp = "{:url('disabled', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        layer.confirm('您确定要修改该数据状态吗', {}, function () {
            $.ajax({
                url: url,
                data: {},
                type: 'POST',
                success: function (e) {
                    layer.msg('操作成功', {icon: 1});
                    window.location.href = e.data.url;
                },
                error: function () {
                    layer.msg('操作失败', {icon: 2});
                }
            })
        });
    });

    // 提交表单
    function toSubmit(url) {
        url = url ? url : "{:url('form')}";
        if(url == "/admin/coupon/form.html"){
            var money = $("#money");
            
            if (typeof(money) != "undefined"){
                if(money.val() <= 0){
                    layer.msg("金额不能小于0", {icon: 2});
                    return false;
                }
            }
            
            
        }
        $.ajax({
            type: 'POST',
            url: url,
            dataType: 'JSON',
            data: $("form").serialize(),
            success: function (e) {
                if (e.code > 0) {
                    layer.msg(e.msg, {icon: 2});
                } else {
                    layer.msg(e.msg, {icon: 1});
                    if (e.data.url) {
                        setTimeout(function () {
                            window.location.href = e.data.url;
                        }, 500);
                    }
                }
            }
        });
        return false;
    }

    // 全选反选
    $('.table-elem #checkbox-all').click(function () {
        $('.table-elem .checkbox-item').prop('checked', $(this).prop('checked'));
    });

    // 获取批量选中的数据
    function getIds() {
        let idsArray = [];
        $.each($('.table-elem .checkbox-item:checked'), function (key, element) {
            idsArray.push($(element).val());
        });
        return idsArray;
    }

    // 批量操作
    function actionAll(url) {
        let ids = getIds();
        if (ids.length <= 0) {
            layer.alert('请选择要操作的数据');
            return false;
        }
        layer.confirm('您确定要批量操作吗？', {}, function () {
            $.ajax({
                url: url,
                data: {
                    ids: ids
                },
                type: 'POST',
                success: function (e) {
                    if (e.code > 0) {
                        layer.alert(e.msg);
                    } else {
                        layer.alert('批量操作成功', {}, function () {
                            if (e.data.url) {
                                window.location.href = e.data.url;
                            }
                        });
                    }
                },
                error: function () {
                    layer.alert('批量操作失败');
                }
            })
        });
    }
</script>
</body>
</html>